<template>
    <div class="investOperate">
        <el-dialog
        :visible.sync="dialog.bool"
        center
        :close-on-click-modal="false"
        >
            <el-form ref="investForm" :model="investForm" status-icon :rules="rules" label-width="120px" size="mini">
                <el-form-item label="项目名称" prop="commodity_name">
                    <el-input v-model="investForm.commodity_name" placeholder="请输入项目名称"></el-input>
                </el-form-item>
                <el-form-item label="产品类型" placeholder="请输入产品类型" prop="type">
                    <el-radio-group v-model="investForm.type" >
                      <el-radio-button label="新手入门"></el-radio-button>
                      <el-radio-button label="热门投资"></el-radio-button>
                      <el-radio-button label="稳定投资"></el-radio-button>
                      <el-radio-button label="高端领投"></el-radio-button>
                    </el-radio-group>
                </el-form-item>
                <el-form-item label="满仓金额" prop="money_up">
                    <el-input v-model.number="investForm.money_up" placeholder="请输入满仓金额" ></el-input>
                </el-form-item>
                <el-form-item label="起投金额" prop="money_down">
                    <el-input v-model="investForm.money_down"placeholder="请输入起投金额" ></el-input>
                </el-form-item>
                <el-form-item label="日利率" prop="day_income">
                    <el-input v-model="investForm.day_income"placeholder="请输入日利率" ></el-input>
                </el-form-item>
                <el-form-item label="项目时长" prop="period">
                    <el-input v-model="investForm.period"placeholder="请输入项目时长" ></el-input>
                </el-form-item>
                <el-form-item label="是否可复投" prop="is_repetition">
                    <el-radio-group v-model="investForm.is_repetition" >
                      <el-radio label="是"></el-radio>
                      <el-radio label="否"></el-radio>
                    </el-radio-group>
                 </el-form-item>
                <el-form-item label="合作承保单位" prop="company">
                    <el-input v-model="investForm.company" placeholder="请输入合作承保单位" ></el-input>
                </el-form-item>
                <el-form-item label="金额及计算规则" prop="money_rule">
                    <el-input type="textarea" v-model="investForm.money_rule"></el-input>
                </el-form-item>
                <el-form-item label="安全保障计划" prop="safety_plan">
                    <el-input type="textarea" v-model="investForm.safety_plan"></el-input>
                </el-form-item>
                <el-form-item label="资金去向" prop="fund_whither">
                    <el-input type="textarea" v-model="investForm.fund_whither" placeholder="请输入资金去向"></el-input>
                </el-form-item>
                <el-form-item label="标签" prop="label">
                    <el-checkbox-group v-model="investForm.label">
                      <el-checkbox label="保本保息" name="label"></el-checkbox>
                      <el-checkbox label="可复投" name="label"></el-checkbox>
                    </el-checkbox-group>
                </el-form-item>
                <el-form-item label="进度">
                    <el-slider
                      v-model="investForm.schedule"
                      show-input>
                    </el-slider>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="submitForm('investForm')">立即创建</el-button>
                </el-form-item>
            </el-form>

        </el-dialog>
    </div>
</template>

<script>
    export default {
        props:["dialog"],
        data(){
                return{
                    investForm:{
                      type:'',
                      money_up:'',
                      money_down:'',
                      day_income:'',
                      period:'',
                      commodity_name:'',
                      is_repetition:'',
                      company:'',
                      money_rule:'',
                      fund_whither:'',
                      safety_plan:'',
                      label:[],
                      schedule:0
                    },
                    rules:{
                        type:[
                           { required: true,message:'请选择产品类型',trigger: 'change'}
                        ],
                        commodity_name:[
                          {  required: true,message:'请输入项目名称',trigger: 'blur'}
                        ],
                        money_up:[
                            {type:'number', required: true,message:'请输入正确的金额',trigger:'blur'}

                        ],
                        day_income:[
                            {required: true,message:'请输入日利率',trigger:'blur'}
                        ],
                        period:[
                            {required: true,message:'请输入项目时长',trigger:'blur'}
                        ],
                        company:[
                            {required: true,message:'请输入合作承保单位',trigger:'blur'}
                        ],
                        money_rule:[
                            {required: true,message:'请输入金额及计算收益规则',trigger:'blur'}
                        ],
                        fund_whither:[
                            {required: true,message:'请输入资金去向',trigger:'blur'}
                        ],
                        safety_plan:[
                            {required: true,message:'请输入安全保障计划',trigger:'blur'}
                        ],
                        label:[
                            {required: true,message:'请至少选择一个标签',trigger:'change'}
                        ],
                        schedule:[
                            {required: true,message:'请输入进度',trigger:'blur'},
                        ],
                        is_repetition:[
                            {required: true,message:'请选择是否可投',trigger:'blur'}
                        ],
                    }
              }
          },
        methods:{
              submitForm(form){
                   this.$refs[form].validate((valid) => {
                            if(valid){
                                if(this.investForm.type == "新手入门"){
                                    this.investForm.type = 1
                                }else if(this.investForm.type == "热门投资"){
                                    this.investForm.type = 2
                                }else if(this.investForm.type == "稳定订投"){
                                    this.investForm.type = 3
                                 }else if(this.investForm.type == "高端领投"){
                                    this.investForm.type = 4
                                 }
                                 if(this.investForm.is_repetition == "是"){
                                    this.investForm.is_repetition = 1
                                 }else if (this.investForm.is_repetition == "否"){
                                    this.investForm.is_repetition = 2
                                 }
                                 this.$post_('invest/invest/add',this.investForm,(res) => {
                                      this.$message({
                                          message:"添加成功",
                                           type: 'success',
                                           duration : 2000
                                      })
                                        setTimeout(()=>{
                                             this.dialog.bool = false;
                                             window.location.reload();
                                        },1800);
                                
                                 })
                                 
                            }else{
                                 return false
                            }
                   })
              }
        }

    }
</script>

<style>
</style>
